package org.tarena.dang.action.cart;

import java.util.List;

import org.tarena.dang.action.BaseAction;
import org.tarena.dang.entity.CartItem;
import org.tarena.dang.service.CartFactory;
import org.tarena.dang.service.CartService;
import org.tarena.dang.util.Constant;

public class CartAction extends BaseAction {
	private List<CartItem> buyList;
	private List<CartItem> delList;
	private int id;
	private int pnum;
	private double blance;
	private double count;
	private boolean ok = true;
	
	public String execute(){
		CartService cart = CartFactory.getCart(session);
		System.out.println("cart action执行了 "+id);
		CartService cartService  = (CartService)session.get(Constant.CART);
		buyList = cart.getBuyList();
		delList = cart.getDelList();
		System.out.println("页面获取删除产品数量===="+delList.size());
		count = cart.count();
		blance = cart.blance();
		
		System.out.println("^^^^^^^^^"+cartService.getBuyList().size());
		session.put(Constant.CART, cartService);
		return "success";
	}
	public String del(){
		System.out.println("删除操作执行了 "+id);
		CartService cartService  = (CartService)session.get(Constant.CART);
		cartService.del(id);
		System.out.println("删除^^^^^剩余^^^^"+cartService.getDelList().size());
		session.put(Constant.CART, cartService);
		return "success";
	}
	public String recovery(){
		System.out.println("恢复操作执行了 "+id);
		CartService cartService  = (CartService)session.get(Constant.CART);
		cartService.recovery(id);
		System.out.println("^^^^^^^^^"+cartService.getBuyList().size());
		session.put(Constant.CART, cartService);
		return "success";
	}
	public String update(){
		System.out.println("更新操作执行了 "+id);
		CartService cartService  = (CartService)session.get(Constant.CART);
		cartService.update(id, pnum);
		System.out.println("^^^^^^^^^"+cartService.getBuyList().size());
		session.put(Constant.CART, cartService);
		return "success";
	}
	public List<CartItem> getBuyList() {
		return buyList;
	}
	public void setBuyList(List<CartItem> buyList) {
		this.buyList = buyList;
	}
	public List<CartItem> getDelList() {
		return delList;
	}
	public void setDelList(List<CartItem> delList) {
		this.delList = delList;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getPnum() {
		return pnum;
	}
	public void setPnum(int pnum) {
		this.pnum = pnum;
	}
	public double getBlance() {
		return blance;
	}
	public void setBlance(double blance) {
		this.blance = blance;
	}
	public double getCount() {
		return count;
	}
	public void setCount(double count) {
		this.count = count;
	}
	public boolean isOk() {
		return ok;
	}
	public void setOk(boolean ok) {
		this.ok = ok;
	}
	
	
}
